package com.bachongLightNovel.works.controller;

import com.bachongLightNovel.model.dto.works.BrowseDto;
import com.bachongLightNovel.model.pojo.works.Novel;
import com.bachongLightNovel.model.vo.page.PageVo;
import com.bachongLightNovel.model.vo.works.BrowseVo;
import com.bachongLightNovel.result.Result;
import com.bachongLightNovel.works.service.WorksBrowseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author vermouth
 */

@RestController
@RequestMapping("/api/works/browse")
@Slf4j
public class WorksBrowseController {

    @Autowired
    private WorksBrowseService worksBrowseService;


    /**
     * 分页查询已发布通过的小说列表集合
     * @param current: 当前页
     * @param size:    每页显示记录数
     * @param dto:     请求条件
     * @return Result
     */
    @PostMapping("get-pass-list/{current}/{size}")
    public Result getPassList(@PathVariable Integer current,
                              @PathVariable Integer size,
                              @RequestBody BrowseDto dto) {
        log.info("分页查询已发布通过的小说列表集合,current:{},size:{},query:{}", current, size, dto);
        PageVo<BrowseVo> vo = worksBrowseService.getPassList(current, size, dto);
        return Result.success(vo);
    }

    /**
     * 更改当前用户的收藏状态
     * @param collect:
     * @param novelId:
     * @return Result
     */
    @PutMapping("update-collect/{collect}/{novelId}")
    public Result update(@PathVariable Boolean collect,
                         @PathVariable Long novelId) {
        log.info("更改当前用户的收藏状态,{},{}", collect, novelId);
        worksBrowseService.updateCollect(collect,novelId);
        return Result.success();
    }

    /**
     * 获取当前登录用户的收藏列表
     * @param :
     * @return Result
     * @author vermouth
     */
    @GetMapping("get-collects")
    public Result getCollects(){
        log.info("获取当前登录用户的收藏列表");
        List<BrowseVo>list=worksBrowseService.getCollects();
        return Result.success(list);
    }
}
